package com.agile.java_seetaface.faceregister;


import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.Socket;

/**
 * @Author ChenZhangKun
 * @Date 2020/4/15 16:40
 */
public class SocketTest {

    static BufferedImage bimg;

    public static void main(String[] args) throws InterruptedException {
        //
         String serverName = "192.168.89.126";
       // String serverName="localhost";
        int[] ports = {8000};
        try {
            System.out.println("Connecting to " + serverName + " on port " + ports);
            // 循环发送
            //\\qtproject\\data\\test_face_recognizer\\face"
            String filePath="D:\\czk\\qtproject\\data\\test_face_recognizer";
            //String filePath = "D:\\czk\\qtproject\\data";
            File file = new File(filePath);
            File[] files = file.listFiles();
            System.out.println(files.length);
            int i = 0;
            for (File file1 : files) {
                if (file1.getName().endsWith("jpg") || file1.getName().endsWith("png")) {

                        for (int port : ports) {
                            Socket client = new Socket(serverName, port);
                            System.out.println(client);
                            File file2 = new File(filePath + "\\" + file1.getName());
                            bimg = ImageIO.read(file2);
                            Thread.sleep(100);
                            ImageIO.write(bimg, "jpg", client.getOutputStream());
                            System.out.println("Image sent!!!!");
                            i++;
                            System.out.println(i + "   " + file1.getName());
                            client.close();
                        }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

